<?php

namespace app\qsapi\service;


use app\qsapi\model\BoxBannerLog;
use think\Db;
use think\Exception;

class BannerPointService extends BaseService
{


    /**
     * 点击banner,埋点接口
     * @param $member_id
     * @param $params
     * @return array
     */
    public function clickBanner($member_id, $params): array
    {
        // write_log('INFO', 'loginByPass.php', 'banner广告参数:'.json_encode($params), 'box_username_login', true);
        try {
            $ip = get_client_ip();
            $ip_info = ip2city($ip);
            $gameStart = new BoxBannerLog();
            $res       = $gameStart->insert([
                'member_id'   => $member_id,
                'ad_id'       => $params['ad_id'] ?? '',
                'ip'          => $ip ?? '',
                'sdk_version' => $params['sdk_version'] ?? '',
                'network'     => isset($params['network']) ? json_decode('"' . $params['network'] . '"') : '',
                'net_isp'     => isset($params['net_isp']) ? json_decode('"' . $params['net_isp'] . '"') : '',
                'sys_version' => $params['sys_version'] ?? '',
                'device_name' => $params['device_name'] ?? '',
                'port'        => $_SERVER['REMOTE_PORT'] ?? '',
                'province'    => $ip_info['province'] ?? '',
                'city'        => $ip_info['city'] ?? '',
                'area'        => $ip_info['area'] ?? '',
                'idfa'        => $params['idfa'] ?? '',
                'caid'        => $params['caid'] ?? '',
                'android_id'  => $params['android_id'] ?? '',
                'oaid'        => $params['oaid'] ?? '',
                'platform'    => $this->device[$this->platform] ?? 0,
                'bundle_id'   => $params['bundle_id'] ?? $this->packname,
                'device'      => $params['device'] ?? '',
            ]);
            if (empty($res)) {
                throw new Exception('添加点击Banner记录失败！');
            }
            return api_message([], '添加点击Banner埋点数据保存成功', 200);
        } catch (Exception $e) {
            return api_message([], $e->getMessage(), 0);
        }
    }


}